package com.assumejson.aop.postprocessor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @author by gang.Li 2022/3/20 20:56
 */
@Component
public class MyBeanPostProcessor implements BeanPostProcessor {
	private static final String NAME = "orderService";
	private static final String NAME1 = "userService1";

	@Override
	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		if (NAME.equals(beanName)) {
			System.out.println("初始化前的后置处理器" + bean.getClass());
		}
		if (NAME1.equals(beanName)) {
			System.out.println("初始化前的后置处理器" + bean.getClass());
		}
		return BeanPostProcessor.super.postProcessBeforeInitialization(bean, beanName);
	}

	@Override
	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		if (NAME.equals(beanName)) {
			System.out.println("初始化后的后置处理器" + bean.getClass());
		}
		if (NAME1.equals(beanName)) {
			System.out.println("初始化后的后置处理器" + bean.getClass());
		}
		return BeanPostProcessor.super.postProcessAfterInitialization(bean, beanName);
	}
}
